/*
参数说明：
alertShow-弹出框参数{
  showmsg-服务器弹窗提示
  msg-服务器提示内容
}
*/
<template>
  <div>
    <alert v-model="alertShow.showmsg" :title="'提示'" @on-show="onShow" @on-hide="onHide">{{alertShow.msg}}</alert>
    <div  style="font-size: 0">
      <img  v-for="subjectitem in subjectList" :src="subjectitem.picUrl" @click="shopinfoFn(subjectitem)" style="width:100%;display:block" alt="专题图片">
    </div>
    <!--<div v-for="pic in pic" style="font-size: 0">-->
      <!--<img :src="pic"  style="width:100%;display:block" alt="专题图片">-->
    <!--</div>-->
  </div>
</template>

<script>
  import { Card, Alert } from 'vux'
  import * as urls from '../../../api/urls'
  import * as types from '../../../store/types'

  export default {
    components: {
      Card,
      Alert
    },
    mounted: function () {
      this.id = this.$route.query.id
      if (this.$store.state.userInfo.id === '' || this.$store.state.userInfo.id === null || this.$store.state.userInfo.id === undefined) {
        let userId = window.location.href.replace(/.*userId=(\w*)&?.*/, '$1')
        let id = window.location.href.replace(/.*id=(\w*)&?.*/, '$1')
        this.userId = userId
        this.id = id
        if (this.userId !== '' && this.userId !== null && this.userId !== undefined) {
          this.$store.commit(types.USER_INFO, {id: this.userId})
          this.getList()
          this.weixinfn3()
        } else {
          let url = window.location.origin
          window.location.href = url + '/api/wxAuth/index?type=t1'
        }
      } else {
        this.getList()
        this.diyweixinfn3()
      }
    },
    data () {
      return {
        pic: ['https://cdn.xiaotaojiang.com/uploads/56/4b3601364b86fdfd234ef11d8712ad/_.jpg', 'https://cdn.xiaotaojiang.com/uploads/56/4b3601364b86fdfd234ef11d8712ad/_.jpg', 'https://cdn.xiaotaojiang.com/uploads/56/4b3601364b86fdfd234ef11d8712ad/_.jpg'],
        alertShow: {
          showmsg: false,
          msg: ''
        },
        subjectList: [],
        subject: {},
        id: ''
      }
    },
    methods: {
      getList () {
        let that = this
        this.http(urls.subjectDetail, {id: that.id}, function (res) {
          if (res.status === 100) {
            if (res.data.items.length !== 0) {
              that.subjectList = res.data.items
            }
          } else {
            that.alertShow.showmsg = true
            that.alertShow.msg = res.errMsg
          }
        }, function (res) {
          that.alertShow.showmsg = true
          that.alertShow.msg = res
        })
      },
      shopinfoFn (item) {
        if (item.itemOrNot === 1) {
          window.localStorage.setItem('shopId', item.itemId)
          let userId = this.$store.state.userInfo.id
          window.localStorage.setItem('userId', userId)
          this.$router.push({
            path: '/ShopInfo'
          })
          this.$router.go(1)
        }
      },
      onShow () {
        // 弹窗出现时触发
      },
      onHide () {
        // 弹窗关闭时触发
      },
      diyweixinfn3 () {
        let that = this
        let userId = this.$store.state.userInfo.id
        let url = window.location.origin
        let link = url + '/api/wxAuth/index?type=t9&id=' + that.id + '&uid=' + userId
        that.$wechat.onMenuShareAppMessage({
          title: that.subject.name, // 分享标题
          desc: '', // 分享描述
          link: link, // 分享链接
          imgUrl: that.subject.bannerUrl, // 分享图标
          success: function () {
            // 用户确认分享后执行的回调函数
          },
          cancel: function () {
            // 用户取消分享后执行的回调函数
          }
        })
        that.$wechat.onMenuShareTimeline({
          title: that.subject.name, // 分享标题
          link: link, // 分享链接
          imgUrl: that.subject.bannerUrl, // 分享图标
          success: function () {
            // 用户确认分享后执行的回调函数
          },
          cancel: function () {
            // 用户取消分享后执行的回调函数
          }
        })
      }
    }
  }
</script>
<style scoped="scoped">
</style>
